package com.hqd.jjvm.classformat.constantpool;

import com.hqd.jjvm.classformat.ClassFile;
import com.hqd.jjvm.rtda.heap.ref.JClassRef;
import com.hqd.jjvm.rtda.heap.ref.JInterfaceMethodRef;
import lombok.Getter;

import java.util.List;

@Getter
public class ConstantInterfaceMethodRefInfo extends ConstantRef {
	public ConstantInterfaceMethodRefInfo(ConstantInfoType tag, ClassFile classFile) {
		super(tag, classFile);
	}

	@Override
	public JInterfaceMethodRef getVal() {
		List<ConstantPool> constantPools = classFile.getConstantPools();
		ConstantNameAndTypeInfo nameAndTypeInfo = (ConstantNameAndTypeInfo) constantPools.get(getNameAndTypeIndex());
		JInterfaceMethodRef interfaceMethodRef = new JInterfaceMethodRef();
		interfaceMethodRef.setDescriptor(constantPools.get(nameAndTypeInfo.getDescriptorIndex()).getVal().toString());
		interfaceMethodRef.setName(constantPools.get(nameAndTypeInfo.getNameIndex()).getVal().toString());
		interfaceMethodRef.setClassName(((JClassRef) constantPools.get(getClassIndex()).getVal()).getClassName());
		return interfaceMethodRef;
	}
}
